package me.zhengjie.modules.common.rest;

import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.common.domain.TEngineerMoney;
import me.zhengjie.modules.common.service.TEngineerMoneyService;
import me.zhengjie.modules.common.service.dto.TEngineerMoneyQueryCriteria;
import me.zhengjie.utils.HttpResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api")
public class TEngineerMoneyController {

    @Autowired
    private TEngineerMoneyService tEngineerMoneyService;

    @Log("查询TEngineerMoney")
    @GetMapping(value = "/tEngineerMoney")
    @ApiOperation("查询TEngineerMoney")
    @PreAuthorize("hasAnyRole('ADMIN','TCUSTOMERCONTRACT_ALL','TCUSTOMERCONTRACT_SELECT','TSERVICEPROVIDERCONTRACT_ALL','TSERVICEPROVIDERCONTRACT_SELECT')")
    public ResponseEntity getTEngineerMoneyList(TEngineerMoneyQueryCriteria criteria){
        return new ResponseEntity(tEngineerMoneyService.queryAll(criteria), HttpStatus.OK);
    }

    @Log("新增TEngineerMoney")
    @PostMapping(value = "/tEngineerMoney")
    @PreAuthorize("hasAnyRole('ADMIN','TCUSTOMERCONTRACT_ALL','TCUSTOMERCONTRACT_CREATE','TSERVICEPROVIDERCONTRACT_ALL','TSERVICEPROVIDERCONTRACT_CREATE')")
    public ResponseEntity create(@Validated @RequestBody List<TEngineerMoney> resources){
        return new ResponseEntity(tEngineerMoneyService.create(resources),HttpStatus.CREATED);
    }

    @Log("修改TEngineerMoney")
    @PutMapping(value = "/tEngineerMoney")
    @PreAuthorize("hasAnyRole('ADMIN','TCUSTOMERCONTRACT_ALL','TCUSTOMERCONTRACT_EDIT','TSERVICEPROVIDERCONTRACT_ALL','TSERVICEPROVIDERCONTRACT_EDIT')")
    public ResponseEntity update(@Validated @RequestBody List<TEngineerMoney> resources){
        tEngineerMoneyService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @Log("删除TEngineerMoney")
    @PostMapping(value = "/tEngineerMoney/delete/list")
    @PreAuthorize("hasAnyRole('ADMIN','TCUSTOMERCONTRACT_ALL','TCUSTOMERCONTRACT_DELETE','TSERVICEPROVIDERCONTRACT_ALL','TSERVICEPROVIDERCONTRACT_DELETE')")
    public ResponseEntity delete(@Validated @RequestBody List<TEngineerMoney> resources){
        try {
            tEngineerMoneyService.delete(resources);
            return new ResponseEntity(HttpStatus.OK);
        }catch (Exception ex) {
            ex.printStackTrace();
            return HttpResponseUtils.passDefaultResponse(ex);
        }
    }
}
